Add a data attribute `data-with-event-mode` to each Dry Run button

Akinori MUSHA 9 years ago
parent
commit
464d4948ff
3 changed files with 14 additions and 2 deletions
  1. 12 0
      app/helpers/agent_helper.rb
  2. 1 1
      app/views/agents/_action_menu.html.erb
  3. 1 1
      app/views/agents/_options.erb

+ 12 - 0
app/helpers/agent_helper.rb

@@ -37,4 +37,16 @@ module AgentHelper
37 37
       }.join(delimiter).html_safe
38 38
     end
39 39
   end
40
+
41
+  def agent_dry_run_with_event_mode(agent)
42
+    case
43
+    when agent.cannot_receive_events?
44
+      'no'.freeze
45
+    when agent.cannot_be_scheduled?
46
+      # incoming event is the only trigger for the agent
47
+      'yes'.freeze
48
+    else
49
+      'maybe'.freeze
50
+    end
51
+  end
40 52
 end

+ 1 - 1
app/views/agents/_action_menu.html.erb

@@ -7,7 +7,7 @@
7 7
 
8 8
   <% if agent.can_dry_run? %>
9 9
     <li>
10
-      <%= link_to icon_tag('glyphicon-refresh') + ' Dry Run', '#', 'data-action-url' => dry_run_agent_path(agent), tabindex: "-1", onclick: "Utils.handleDryRunButton(this)" %>
10
+      <%= link_to icon_tag('glyphicon-refresh') + ' Dry Run', '#', 'data-action-url' => dry_run_agent_path(agent), 'data-with-event-mode' => agent_dry_run_with_event_mode(agent), tabindex: "-1", onclick: "Utils.handleDryRunButton(this)" %>
11 11
     </li>
12 12
   <% end %>
13 13
 

+ 1 - 1
app/views/agents/_options.erb

@@ -25,6 +25,6 @@
25 25
 <div class="form-group">
26 26
   <%= submit_tag "Save", :class => "btn btn-primary" %>
27 27
   <% if agent.can_dry_run? %>
28
-    <%= button_tag class: 'btn btn-default agent-dry-run-button', type: 'button', 'data-action-url' => agent.persisted? ? dry_run_agent_path(agent) : dry_run_agents_path do %><%= icon_tag('glyphicon-refresh') %> Dry Run<% end %>
28
+    <%= button_tag class: 'btn btn-default agent-dry-run-button', type: 'button', 'data-action-url' => agent.persisted? ? dry_run_agent_path(agent) : dry_run_agents_path, 'data-with-event-mode' => agent_dry_run_with_event_mode(agent) do %><%= icon_tag('glyphicon-refresh') %> Dry Run<% end %>
29 29
   <% end %>
30 30
 </div>